<template>
	<view class="p20">
		<view class="p20 bg-fff radius20">
			<u-form :model="form" ref="uForm" :border-bottom="false" labelWidth="auto">
				<view class="bg-f7f pl20 pr20 mt20 radius20">
					<u-form-item label="姓名" class="color9" prop="username">
						<u-input input-align="right" v-model="form.username" placeholder="请输入姓名" />
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20">
					<u-form-item label="手机号" class="color9" prop="mobile">
						<u-input input-align="right" maxlength="11" type="number" v-model="form.mobile" placeholder="请输入手机号" />
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20">
					<u-form-item label="账号类型" class="color9">
						<view slot="right" class="color-666 flex">
							<view class="flex ml20" @click="form.method=key" v-for="(value,key) in methodList"
								:key="key">
								<view class=" mr10">{{value}}</view>
								<u-icon name="checkmark-circle-fill" :color="$zs" v-if="form.method==key" />
								<u-icon name="checkmark-circle" v-else />
							</view>
						</view>
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20">
					<u-form-item label="账号" class="color9" prop="account">
						<u-input input-align="right" v-model="form.account"
							:placeholder="`请输入${methodList[form.method]}账号`" />
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20" v-if="form.method=='bank'">
					<u-form-item label="开户行名称" class="color9" prop="bank_name">
						<u-input input-align="right" v-model="form.bank_name" placeholder="请输入开户行名称" />
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20" v-if="form.method!='bank'">
					<u-form-item label="收款码" class="color9" >
						<view class="" slot="right">
							<imgList @success="e=>form.qrcode=e" text="上传收款码" />
						</view>
					</u-form-item>
				</view>
				<view class="bg-f7f pl20 pr20 mt20 radius20" >
					<u-form-item label="默认" class="color9" >
						<view class="" slot="right">
							<switch class="scale7" :checked="form.is_default==1"
								@change="e=>form.is_default=e.detail.value*1" :color="$zs" />
						</view>
					</u-form-item>
				</view>
			</u-form>
		</view>
		<view class="mt80">
			<u-button type="error" class="w710" @click="submit()">完成</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				methodList: {
					"wechat": '微信',
					"alipay": '支付宝',
					"bank": '银行卡',
				},

				form: {
					// id: "", //	整型	必填	-	-	账户id（编辑时有此参数）
					username: "", //	字符串	必填	-	-	姓名
					mobile: "", //	字符串	必填	-	-	手机号
					method: "wechat", //	字符串	必填	-	-	方式:wechat=微信,alipay=支付宝,bank=银行卡
					account: "", //	字符串	必填	-	-	微信/支付宝/银行卡账号
					qrcode: "", //	字符串	必填	-	-	收款码
					bank_name: "", //	字符串	必填	-	-	开户行名称
					is_default: "", //	整型	必填	-	-	是否默认：0不默认，1默认
				},
				bankShow: false, //选择银行
				bankList: [],
				rules: {
					bankCode: [{
						required: true,
						message: '请选择银行',
						trigger: ['change', 'blur'],
					}],
					username: [{
						required: true,
						message: '持卡人姓名不能为空',
						trigger: ['change', 'blur'],
					}],
					mobile: [{
							required: true,
							message: '手机号不能为空',
							trigger: ['change', 'blur'],
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							trigger: ['change', 'blur'],
						}
					],
					cardCode: [{
						required: true,
						message: '账户/账号不能为空',
						trigger: ['change', 'blur'],
					}, ],
				}
			}
		},
		onLoad(e) {
			// for (let key in this.form) {
			// 	this.form[key] = e[key]
			// }
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (!valid) return
					this.$request('/master/withdraw/accountAdd', {
						...this.form,
						...this.$params,
					}).then(res => {
						this.$msg(res.msg)
						setTimeout(this.$navBack, 1000)
					})
				});
			},
			bankCode_text(bankCode) {
				let aa = this.bankList?.find(e => e.bankCode == bankCode)?.bankName || bankCode
				this.form.bankName = aa
				return aa
			},
		}
	}
</script>

<style scoped lang="scss">

</style>
